﻿using System;
using System.IO;

namespace Toybox.SCM.Models.Configs
{
	using NicoSharp.Abstracts;
	using NicoSharp.Utilities;

	public class ExtraConfig : AbstractNotifyObject
	{

		#region [Static]

		/// <summary>
		/// ファイルからその他設定を読み込む
		/// </summary>
		/// <returns></returns>
		public static ExtraConfig Load(string path)
		{
			try
			{
				using (FileStream fs = new FileStream(path, FileMode.Open))
				{
					return Deserializer.XmlDeserializer<ExtraConfig>(fs);
				}
			}
			catch (Exception ex)
			{
				return new ExtraConfig();
			}
		}

		/// <summary>
		/// ファイルへその他設定を書き込む
		/// </summary>
		/// <returns></returns>
		public static void Save(string path, ExtraConfig config)
		{
			try
			{
				using (FileStream fs = new FileStream(path, FileMode.Create))
				{
					Serializer.XmlSerializer<ExtraConfig>(fs, config);
				}
			}
			catch (Exception ex)
			{
			}
		}

		#endregion [Static]


		#region Constructor

		/// <summary>
		/// コンストラクタ
		/// </summary>
		public ExtraConfig()
		{
			// デフォルト値
			this.UserAgent = "Second Comment Master";
			this.MaxCount = 5;
		}

		#endregion Constructor


		#region Public Members
		
		/// <summary>
		/// アカウント登録最大数
		/// </summary>
		public int MaxCount
		{
			get { return this._maxCount; }
			set
			{
				if (this._maxCount == value) return;
				this._maxCount = value;
				base.OnPropertyChanged("MaxCount");
			}
		}
		private int _maxCount;

		/// <summary>
		/// ユーザエージェント
		/// </summary>
		public string UserAgent
		{
			get { return NicoSharp.Utilities.NicoWebClient.UserAgent; }
			set
			{
				if (NicoSharp.Utilities.NicoWebClient.UserAgent == value) return;
				NicoSharp.Utilities.NicoWebClient.UserAgent = value;
				base.OnPropertyChanged("UserAgent");
			}
		}

		#endregion Public Members

	}
}
